package org.beetl.sql2o.converters;

import java.math.BigDecimal;

/**
 * Used by sql2o to convert a value from the database into a {@link BigDecimal}.
 */
public class BigDecimalConverter extends NumberConverter<BigDecimal> {

 public BigDecimalConverter() {
  super(false);
 }

 protected BigDecimal convertNumberValue(Number val) {
  if (val.getClass().equals(BigDecimal.class)) {
   return (BigDecimal) val;
  } else {
   return BigDecimal.valueOf(val.doubleValue());
  }
 }

 protected BigDecimal convertStringValue(String val) {
  return BigDecimal.valueOf(Double.parseDouble(val));
 }

 protected String getTypeDescription() {
  return BigDecimal.class.toString();
 }
}
